package com.ezonsport.android.ui;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;

import com.ezonsport.android.R;

public class PrivacySettings extends PreferenceActivity implements OnPreferenceChangeListener {
	private static final String PREFERENCE_NAME = "ezonsportmobile";
	private static final String KEY_USER_INFORMATION = "privacy_userinformation_setting";
	private static final String KEY_USER_SPORT = "privacy_sportinformation_setting";
	private CheckBoxPreference mUserInformation;
	private CheckBoxPreference mSportInformation;
	private SharedPreferences mSharePre;
	private SharedPreferences.Editor mEditor;
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.privacy_settings);
        mSharePre = getSharedPreferences(PREFERENCE_NAME, MODE_PRIVATE);
        mEditor = mSharePre.edit();
        mUserInformation = (CheckBoxPreference)findPreference(KEY_USER_INFORMATION);
        mSportInformation = (CheckBoxPreference)findPreference(KEY_USER_SPORT);
    }
    
    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
    	if(preference.getKey().equals(KEY_USER_INFORMATION)){
    		mUserInformation.setChecked((Boolean)newValue);
    		mEditor.putInt(KEY_USER_INFORMATION, (Boolean)newValue?1:0);
    		mEditor.commit();
    		
    	}
    	if(preference.getKey().equals(KEY_USER_SPORT)){
    		mEditor.putInt(KEY_USER_SPORT, (Boolean)newValue?1:0);
    		mEditor.commit();
    	}
    		
    	return false;
    }
    
    
}
